package com.module.ble.db

import androidx.sqlite.db.SimpleSQLiteQuery
import androidx.sqlite.db.SupportSQLiteQuery

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2025/08/18
 *
 * 描述：血氧查询辅助类
 *
 * 修订历史：
 *
 */
object BloodOxygenTableQueryHelper {

    /**
     * 根据多个时间段查询heart_rate表数据
     * @param timeRanges 时间段数组，每个Pair的first为开始时间戳，second为结束时间戳
     * @return SupportSQLiteQuery
     */
    fun createMultiTimeRangeQuery(timeRanges: List<Pair<Long, Long>>): SupportSQLiteQuery {
        if (timeRanges.isEmpty()) {
            throw IllegalArgumentException("Time ranges array cannot be empty")
        }

        // 构建多个时间段的OR条件SQL语句
        val conditions = timeRanges.joinToString(" OR ") { timeRange ->
            "(createdTime >= ${timeRange.first} AND createdTime <= ${timeRange.second})"
        }

        val sql = "SELECT * FROM blood_oxygen WHERE $conditions ORDER BY createdTime ASC"
        return SimpleSQLiteQuery(sql)
    }
}